<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        .item {
            overflow: hidden;
            padding: 10px;
            width: 400px;
            border: 1px solid red;
        }

        item img {
            width: 100px;
            float: left;
        }

        .film {
            border: 1px solid black;
            height: 1500px;
        }

        .filminfo {
            width: 300px;
            win-height: 200px;
            background: yellow;
            padding: fixed;
            right: 50px;
            top: 100px;
            border: 1px solid blue;
        }
    </style>
</head>

<body>
    <div id="box">
        <button @click="handleAjax">ajax</button>

        <!-- 根据datalist的长度绝对循环的次数和数据的长度 -->
        <!-- 在子组件上放监听事件 -->
        <film-item v-for="data in datalist" :key="data.filmid" 
        :item="data" @myevent="handleEvent"></film-item>


        <film-detail :myinfo="info"></film-detail>
    </div>

    <script type="text/javascript">
        Vue.component("filmDetail", {
            // 接收
            props:["myinfo"],
            template:`
            <div class="filminfo">
               {{myinfo}}
            </div>
            `
        })

        //创建film-item组件
        Vue.component("film-item", {
            props: ["ltem"],
            template: `
                <div class="item">
                   <img :src="item.poster"/>
                  <div> {{ item.name }} </div>
                    <button @click="handleClick()">详情</button>
                </div>`,
                method: {
                    handleClick() {
                        // console.log(this.item.synopsis)
                        this.$emit("myevent", this.item.synopsis) //将数据传给父组件
                    }
                }
        })
        new Vue({
            el: '#box',
            data: {
                datalist: [],
                info:""
            },
            methods: {
                handleAjax() {
                    fetch("https://www.")
                        .then(res => res.)
                        .then(res => {
                            console.log(res.data.films)
                            this.datalist = res.data.films
                        })
                }, 
                handleEvent(info){
                    console.log("父组件执行", info)
                    this.info = info
                }
            }

        })
    </script>
</body>

</html>